package com.lianniu.web.tea.user.collect.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.user.collect.model.TeaCollect;
import com.lianniu.web.tea.user.collect.service.ITeaUserCollectService;

@Controller
@RequestMapping("/rest/user/collect")
public class TeaUserCollectController {

	private final static Logger logger = Logger.getLogger(TeaUserCollectController.class);

	@Autowired
	private ITeaUserCollectService teaUserCollectService;

	@RequestMapping(value = "/addCollect", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult addCollect(HttpServletRequest req) {
		logger.info("TeaUserCollectController  addCollect begin.");
		try {
			logger.info("addCollect begin.");
			String productId = req.getParameter("productId");
			String userId = req.getParameter("userId");
			TeaCollect teaCollect = new TeaCollect();
			teaCollect.setProductId(productId);
			teaCollect.setUserId(Long.valueOf(userId));
			BaseResult baseResult = teaUserCollectService.addCollect(teaCollect);
			logger.info("addCollect end.");
			logger.info("TeaUserCollectController addCollect end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaUserCollectController addCollect error:" + e.getMessage());
			logger.error("TeaUserCollectController addCollect end.");
			return BaseResult.exception(e.getMessage());
		}
	}

	@RequestMapping(value = "/deleteCollect", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult deleteCollect(HttpServletRequest req) {
		logger.info("TeaUserCollectController deleteCollect begin.");
		try {
			logger.info("deleteCollect begin.");
			String id = req.getParameter("id");
			BaseResult baseResult = teaUserCollectService.deleteCollect(id);
			logger.info("deleteCollect end.");
			logger.info("TeaUserCollectController deleteCollect end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaUserCollectController deleteCollect error:" + e.getMessage());
			logger.error("TeaUserCollectController deleteCollect end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	@RequestMapping(value = "/checkCollect", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult checkCollect(HttpServletRequest req) {
		logger.info("TeaUserCollectController checkCollect begin.");
		try {
			logger.info("checkCollect begin.");
			String productId = req.getParameter("productId");
			String userId = req.getParameter("userId");
			BaseResult baseResult = teaUserCollectService.checkCollect(productId,userId);
			logger.info("checkCollect end.");
			logger.info("TeaUserCollectController checkCollect end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaUserCollectController checkCollect error:" + e.getMessage());
			logger.error("TeaUserCollectController checkCollect end.");
			return BaseResult.exception(e.getMessage());
		}
	}

}
